package backend.service.admin;

import backend.model.admin.Workplace;
import backend.service.base.DBModelServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WorkplaceServiceImpl extends DBModelServiceImpl<Workplace> implements WorkplaceService {

    @Override
    public Class<Workplace> getEntityClass() {
        return Workplace.class;
    }

    @Override
    public List<Workplace> findAllWorkplaces() {
        return dbModelDao.findByNamedQuery("findAllWorkplaces");
    }

    @Override
    public List<Workplace> findAllActiveWorkplaces() {
        return dbModelDao.findByNamedQuery("findAllActiveWorkplaces");
    }

    @Override
    public Workplace findWorkplaceByName(String name) {
        List<Workplace> workplacesByName = dbModelDao.findByNamedQueryAndParams("findWorkplaceByName", new String[]{"name"}, new Object[]{name});
        assert workplacesByName.size() <= 1;
        if (workplacesByName.size() == 1) {
            return workplacesByName.get(0);
        }
        return null;
    }
}
